/**
 * TCSS 360 System Q&A
 * Winter Qtr 2013
 * 
 * darksideoftheloom:
 * Michael Wamsley
 * Roger Trottier
 * Shane Kwon
 * Joshua Warner
 */
package darksideoftheloom;

import java.util.ArrayList;
import java.util.Collections;

/**
 * Attendee class. Represents a typical user to an
 * event.
 * 
 * @author Michael Wamsley
 * @version 2-18-2013
 */
public class Attendee {
	
	/**
	 * The number of entries allowed for each contestant.
	 */
	private static final int NUMBER_OF_ENTRIES = 3;
	
	/**
	 * The Attendee's name.
	 */
	private String name;
	
	/**
	 * The Attendee's phone number.
	 */
	private String phonenumber;
	
	/**
	 * The Attendee's address.
	 */
	private String address;
	
	/**
	 * The Attendee's email.
	 */
	private String email;
	
	/**
	 * The Attendee's username.
	 */
	private String username;
	
	/**
	 * The Attendee's password.
	 */
	private String password;
	
	/**
	 * True if user is logged in, false if logged out.
	 */
	private boolean logStatus;
	
	/**
	 * The user's id. The same as their username.
	 */
	private String userID;
	
	/**
	 * The user's submissions.
	 */
	protected ArrayList<Submission> submissions;
	

	/**
	 * Constructs the attendee class.
	 * @param a_name
	 * @param a_phoneNumber
	 * @param a_address
	 * @param a_email
	 * @param a_username
	 * @param a_password
	 */
	public Attendee(final String a_name, final String a_phoneNumber, final String a_address, 
				final String a_email, final String a_username, final String a_password) {
		name = a_name;
		phonenumber = a_phoneNumber;
		address = a_address;
		email = a_email;
		username = a_username;
		password = a_password;
		logStatus = true;
		userID = a_username;
		submissions = new ArrayList<Submission>(NUMBER_OF_ENTRIES);
	}

	/**
	 * Returns name.
	 * @return name.
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * Allows for user to change their registered name.
	 * @param a_name
	 */
	public void setName(final String a_name) {
		this.name = a_name;
	}
	
	/**
	 * Returns a phone number.
	 * @return phonenumber
	 */
	public String getPhoneNumber() {
		return phonenumber;
	}

	/**
	 * Allows for user to change their phone number.
	 * @param a_phonenumber
	 */
	public void setPhoneNumber(final String a_phonenumber) {
		this.phonenumber = a_phonenumber;
	}

	/**
	 * Returns an address.
	 * @return address
	 */
	public String getAddress() {
		return address;
	}

	/**
	 * Allows user to change their address.
	 * @param a_address
	 */
	public void setAddress(final String a_address) {
		this.address = a_address;
	}

	/**
	 * Returns an email
	 * @return email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * Allows a user to change their email.
	 * @param a_email
	 */
	public void setEmail(final String a_email) {
		this.email = a_email;
	}

	/**
	 * Returns a username.
	 * @return username
	 */
	public String getUsername() {
		return username;
	}

	/**
	 * Allows a user to change their username.
	 * @param a_username
	 */
	public void setUsername(final String a_username) {
		this.username = a_username;
		this.userID = a_username;
	}

	/**
	 * Returns a password.
	 * @return password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * Allows a user to change their password.
	 * @param a_password
	 */
	public void setPassword(final String a_password) {
		this.password = a_password;
	}
	
	/**
	 * Allows a user to submit a submission.
	 * 
	 * @param a_submission
	 */
	public void submit(final Submission a_submission) {
		if (submissions.size() >= NUMBER_OF_ENTRIES) {
			throw new IllegalArgumentException("You have already submitted 3 entries!");
		} else {
			for (Submission sub: submissions) {
				if (a_submission.getCategory() == sub.getCategory()) {
					throw new IllegalArgumentException("You have already submitted an entry" +
							" to this category");
				}
			}
			submissions.add(a_submission);
		}
	}

	/**
	 * Returns the submissions.
	 * @return submissions
	 */
	public ArrayList<Submission> getSubmissions() {
		//Defensive copy of the array.
		ArrayList<Submission> copy = new ArrayList<Submission>(submissions.size());
		for (Submission sub: submissions) {
			copy.add(sub);
		}
		return copy;
	}
	
	/**
	 * Removes desired submission.
	 * 
	 * @param a_submission
	 */
	public void removeSubmission(final Submission a_submission) {
		if (submissions.contains(a_submission)) {
			submissions.remove(a_submission);
		}
	}
		
	/**
	 * Sorts the submissions.
	 */
	@SuppressWarnings("unchecked")
	public void sortSubmissions() {
		Collections.sort(submissions);
	}
}
